package io.github.weiranyi.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Description 连接工具类
 * @Return
 * @Author https://weiranyi.github.io
 * @Date Created in 2022-12-19 21:45
 **/
public class ConnectionUtil {
    public static Connection getConnection() throws Exception {
        //1.创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //2.在工厂对象中设置MQ的连接信息（ip,port,vhost,username,password）
        connectionFactory.setHost("10.8.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");
        connectionFactory.setVirtualHost("/cdut");
        //3.通过工厂获得与MQ的连接
        Connection connection = connectionFactory.newConnection();
        return connection;
    }
}
